package com.wmyg.antifake.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wmyg.antifake.bean.FactoryDevice;
import com.wmyg.antifake.bean.QrProduct;
import com.wmyg.antifake.dao.QrProductMapper;
import com.wmyg.antifake.service.QrProductService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QrProductServiceImpl implements QrProductService {

    @Autowired
    QrProductMapper QrProductDao;

    @Override
    public int insertQrProduct (QrProduct qrProduct) {
        if(StringUtils.isNotEmpty(qrProduct.getQrCodeNumber())){
            QrProductDao.deleteQrProductByQrCodeNumber(qrProduct.getQrCodeNumber());
        }
        return QrProductDao.insertQrProduct(qrProduct);
    }

    @Override
    public PageInfo<QrProduct> selectQrProductList (QrProduct qrProduct) {
        PageHelper.startPage(qrProduct.getPageIndex(), qrProduct.getPageSize());
        List<QrProduct> QrProductList = QrProductDao.selectQrProductList(qrProduct);
        return new PageInfo(QrProductList);
    }

    @Override
    public QrProduct selectQrProductByQrCodeNumber (String qrCodeNumber) {
        return QrProductDao.selectQrProductByQrCodeNumber(qrCodeNumber);
    }
}
